<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.1.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/hexo/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/hexo/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/hexo/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/hexo/images/logo.svg" color="#222">

<link rel="stylesheet" href="/hexo/css/main.css">


<link rel="stylesheet" href="/hexo/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"youchen12138.gitee.io","root":"/hexo/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta property="og:type" content="website">
<meta property="og:title" content="幽辰的博客">
<meta property="og:url" content="https://youchen12138.gitee.io/hexo/page/7/index.html">
<meta property="og:site_name" content="幽辰的博客">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="幽辰">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://youchen12138.gitee.io/hexo/page/7/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'en'
  };
</script>

  <title>幽辰的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/hexo/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">幽辰的博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/hexo/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/hexo/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags<span class="badge">23</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/hexo/categories/" rel="section"><i class="fa fa-th fa-fw"></i>Categories<span class="badge">14</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/hexo/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives<span class="badge">127</span></a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-Form%EF%BC%88%E8%A1%A8%E5%8D%95%EF%BC%89%E5%92%8CSnackBar%EF%BC%88%E6%8F%90%E7%A4%BA%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-Form%EF%BC%88%E8%A1%A8%E5%8D%95%EF%BC%89%E5%92%8CSnackBar%EF%BC%88%E6%8F%90%E7%A4%BA%EF%BC%89/" class="post-title-link" itemprop="url">Flutter-Form（表单）和SnackBar（提示）</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:47:49 / Modified: 16:48:01" itemprop="dateCreated datePublished" datetime="2020-08-26T16:47:49+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>我们可以使用flutter自带的<code>Form</code>组件完成表单的创建</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">class RegisterForm extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _RegisterFormState createState() &#x3D;&gt; _RegisterFormState();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br></pre></td><td class="code"><pre><span class="line">class _RegisterFormState extends State&lt;RegisterForm&gt; &#123;</span><br><span class="line">  final registerFormKey &#x3D; GlobalKey&lt;FormState&gt;();</span><br><span class="line">  String username, password;</span><br><span class="line"></span><br><span class="line">  void submitRegisterForm()&#123;</span><br><span class="line">    if(registerFormKey.currentState.validate())&#123;</span><br><span class="line">      registerFormKey.currentState.save();</span><br><span class="line"></span><br><span class="line">      debugPrint(&#39;username: $username&#39;);</span><br><span class="line">      debugPrint(&#39;username: $password&#39;);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  String validateUsername(value)&#123;</span><br><span class="line">    if(value.isEmpty)&#123;</span><br><span class="line">      return &#39;Username is required.&#39;;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    return null; </span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  String validatePassword(value)&#123;</span><br><span class="line">    if(value.isEmpty)&#123;</span><br><span class="line">      return &#39;Password is required.&#39;;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    return null; </span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Form(</span><br><span class="line">      autovalidate: true, &#x2F;&#x2F; 该属性为true，则开启自动校验</span><br><span class="line">      key: registerFormKey, &#x2F;&#x2F; 设置globalKey，用于后面获取FormState</span><br><span class="line">      child: Column(</span><br><span class="line">        children: &lt;Widget&gt;[</span><br><span class="line">          TextFormField(</span><br><span class="line">            decoration: InputDecoration(</span><br><span class="line">              labelText: &#39;Username&#39;,</span><br><span class="line">              helperText: &#39;&#39;,</span><br><span class="line">            ),</span><br><span class="line">            onSaved: (value)&#123;</span><br><span class="line">              username &#x3D; value;</span><br><span class="line">            &#125;,</span><br><span class="line">            validator: validateUsername,</span><br><span class="line">          ),</span><br><span class="line">          TextFormField(</span><br><span class="line">            obscureText: true, &#x2F;&#x2F; 输入为密码</span><br><span class="line">            decoration: InputDecoration(</span><br><span class="line">              labelText: &#39;Password&#39;,</span><br><span class="line">              helperText: &#39;&#39;,</span><br><span class="line">            ),</span><br><span class="line">            onSaved: (value)&#123;</span><br><span class="line">              password &#x3D; value;</span><br><span class="line">            &#125;,</span><br><span class="line">            validator: validatePassword,</span><br><span class="line">          ),</span><br><span class="line">          SizedBox(height: 32,),</span><br><span class="line">          Container(</span><br><span class="line">            width: double.infinity,</span><br><span class="line">            child: RaisedButton(</span><br><span class="line">              color: Theme.of(context).accentColor,</span><br><span class="line">              child: Text(&#39;Register&#39;, style: TextStyle(color: Colors.white),),</span><br><span class="line">              elevation: 0,</span><br><span class="line">              onPressed: submitRegisterForm,</span><br><span class="line">            ),</span><br><span class="line">          )</span><br><span class="line">        ],</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-7398a114b1696e62.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h2 id="SnackBar（提示）"><a href="#SnackBar（提示）" class="headerlink" title="SnackBar（提示）"></a>SnackBar（提示）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">if (registerFormKey.currentState.validate()) &#123;</span><br><span class="line">  registerFormKey.currentState.save();</span><br><span class="line"></span><br><span class="line">  debugPrint(&#39;username: $username&#39;);</span><br><span class="line">  debugPrint(&#39;username: $password&#39;);</span><br><span class="line"></span><br><span class="line">  Scaffold.of(context).showSnackBar(</span><br><span class="line">    SnackBar(</span><br><span class="line">      content: Text(&#39;Registering...&#39;),</span><br><span class="line">    )</span><br><span class="line">  );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-7da9f6dbfa7f3b87.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-%E8%BE%93%E5%85%A5%E6%A1%86/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-%E8%BE%93%E5%85%A5%E6%A1%86/" class="post-title-link" itemprop="url">Flutter-输入框</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:47:11 / Modified: 16:47:23" itemprop="dateCreated datePublished" datetime="2020-08-26T16:47:11+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="TextField（文本输入框）"><a href="#TextField（文本输入框）" class="headerlink" title="TextField（文本输入框）"></a>TextField（文本输入框）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">TextField(</span><br><span class="line">  decoration: InputDecoration(</span><br><span class="line">    icon: Icon(Icons.subject),</span><br><span class="line">    labelText: &#39;Title&#39;, &#x2F;&#x2F; 文字提示</span><br><span class="line">    hintText: &#39;Enter the post title&#39;, &#x2F;&#x2F; 文字提示，类似placeholder</span><br><span class="line">    &#x2F;&#x2F; border: InputBorder.none, &#x2F;&#x2F; 不设置四周边框</span><br><span class="line">    &#x2F;&#x2F; border: OutlineInputBorder() &#x2F;&#x2F; 设置四周边框</span><br><span class="line">    filled: true, &#x2F;&#x2F; 是否填充背景</span><br><span class="line">    fillColor: Colors.grey, &#x2F;&#x2F; 填充颜色</span><br><span class="line">    &#x2F;&#x2F; onChanged: (value)&#123;&#125;, &#x2F;&#x2F; 当输入框内容发生变化时调用的函数</span><br><span class="line">    &#x2F;&#x2F; onSubmitted: (value)&#123;&#125;, &#x2F;&#x2F; 当点击确定时调用的函数</span><br><span class="line">  ),</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
<h3 id="decoration（InputDecoration）属性介绍"><a href="#decoration（InputDecoration）属性介绍" class="headerlink" title="decoration（InputDecoration）属性介绍:"></a>decoration（InputDecoration）属性介绍:</h3><table>
<thead>
<tr>
<th>属性</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>border</td>
<td>增加一个边框，</td>
</tr>
<tr>
<td>hintText</td>
<td>未输入文字时，输入框中的提示文字，</td>
</tr>
<tr>
<td>prefixIcon</td>
<td>输入框内侧左面的控件，</td>
</tr>
<tr>
<td>labelText</td>
<td>一个提示文字。输入框获取焦点/输入框有内容 会移动到左上角，否则在输入框内，labelTex的位置.</td>
</tr>
<tr>
<td>suffixIcon</td>
<td>输入框内侧右面的图标.</td>
</tr>
<tr>
<td>icon</td>
<td>输入框左侧添加图标</td>
</tr>
<tr>
<td>filled</td>
<td>是否填充背景</td>
</tr>
<tr>
<td>fillColor</td>
<td>填充颜色</td>
</tr>
<tr>
<td>onChanged</td>
<td>当输入框内容发生变化时调用的函数</td>
</tr>
<tr>
<td>onSubmited</td>
<td>当点击确定时调用的函数</td>
</tr>
<tr>
<td>errorText</td>
<td>错误提示文字</td>
</tr>
</tbody></table>
<h3 id="controller详解"><a href="#controller详解" class="headerlink" title="controller详解"></a>controller详解</h3><p><code>controller</code>可以理解为该文本框的映射，通过以下方式创建</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">TextEditingController textEditingController &#x3D; TextEditingController();</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">final textEditingController &#x3D; TextEditingController();</span><br></pre></td></tr></table></figure>
<p>以上两种创建方法等效，接下来，我们将要让控制器与对应文本框绑定</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">TextField(</span><br><span class="line">  controller: textEditingController, &#x2F;&#x2F; 控制器绑定</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
<p>至此控制器就创建完成。另外，控制器还有两个默认的方法</p>
<h4 id="dispose"><a href="#dispose" class="headerlink" title="dispose"></a>dispose</h4><p>调用<code>dispose</code>的方法意为在使用完<code>controller</code>后自动卸载，从而优化性能</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">@override</span><br><span class="line">void dispose()&#123;</span><br><span class="line">  textEditingController.dispose(); &#x2F;&#x2F; 卸载该控制器，类似于使用完成后卸载，将优化性能</span><br><span class="line">  super.dispose();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="initState"><a href="#initState" class="headerlink" title="initState"></a>initState</h4><p><code>initState</code>设置初始状态</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">@override</span><br><span class="line">void initState()&#123; &#x2F;&#x2F; 设定控制器初始状态</span><br><span class="line">  super.initState();</span><br><span class="line">  textEditingController.text &#x3D; &#39;hi&#39;; &#x2F;&#x2F; 设置默认值</span><br><span class="line">  textEditingController.addListener( &#x2F;&#x2F; 添加事件监听</span><br><span class="line">    ()&#123;</span><br><span class="line">      debugPrint(&#39;input: $&#123;textEditingController.text&#125;&#39;);</span><br><span class="line">    &#125;</span><br><span class="line">  );</span><br><span class="line">&#125;  </span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-Theme%EF%BC%88%E4%B8%BB%E9%A2%98%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-Theme%EF%BC%88%E4%B8%BB%E9%A2%98%EF%BC%89/" class="post-title-link" itemprop="url">Flutter-Theme（主题）</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:46:42 / Modified: 16:46:59" itemprop="dateCreated datePublished" datetime="2020-08-26T16:46:42+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>我们可以通过<code>Theme</code>组件来替换<code>MaterialApp</code>中的<code>ThemeData</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Theme(</span><br><span class="line">  data: Theme.of(context).copyWith( </span><br><span class="line">  &#x2F;&#x2F; 如果使用ThemeData这个组件，它会在当前组件内完全替代原来的主题；</span><br><span class="line">  &#x2F;&#x2F; 如果使用Theme.of(context).copyWith，它只会覆盖掉设置的这些主题属性</span><br><span class="line">  primaryColor: Colors.black</span><br><span class="line">  ),</span><br><span class="line">  child: ThemeDemo(),</span><br><span class="line">),</span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-%E6%BA%85%E5%A2%A8%E6%95%88%E6%9E%9C%EF%BC%88Inkwell%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-%E6%BA%85%E5%A2%A8%E6%95%88%E6%9E%9C%EF%BC%88Inkwell%EF%BC%89/" class="post-title-link" itemprop="url">Flutter-溅墨效果（Inkwell）</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:45:55 / Modified: 16:46:24" itemprop="dateCreated datePublished" datetime="2020-08-26T16:45:55+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">Stack(</span><br><span class="line">  children: &lt;Widget&gt;[</span><br><span class="line">    Column(</span><br><span class="line">      children: &lt;Widget&gt;[</span><br><span class="line">        AspectRatio(</span><br><span class="line">          aspectRatio: 16&#x2F;9,</span><br><span class="line">          child: Image.network(posts[index].imageUrl, fit: BoxFit.cover,),</span><br><span class="line">        ),</span><br><span class="line">        SizedBox(height: 16,),</span><br><span class="line">        Text(</span><br><span class="line">          posts[index].title,</span><br><span class="line">          style: Theme.of(context).textTheme.title,</span><br><span class="line">        ),</span><br><span class="line">        Text(</span><br><span class="line">          posts[index].author,</span><br><span class="line">          style: Theme.of(context).textTheme.subhead,</span><br><span class="line">        ),</span><br><span class="line">        SizedBox(height: 16,)</span><br><span class="line">      ],</span><br><span class="line">    ),</span><br><span class="line">    Positioned.fill(</span><br><span class="line">      child: Material(</span><br><span class="line">        color: Colors.transparent,</span><br><span class="line">        child: InkWell(</span><br><span class="line">          splashColor: Colors.white.withOpacity(0.3), &#x2F;&#x2F; 慢慢展开的颜色</span><br><span class="line">          highlightColor: Colors.white.withOpacity(0.1), &#x2F;&#x2F; 高亮颜色</span><br><span class="line">          onTap: ()&#123;</span><br><span class="line">            Navigator.of(context).push(</span><br><span class="line">              MaterialPageRoute(</span><br><span class="line">                builder: (context) &#x3D;&gt; PostShow(post: posts[index],)</span><br><span class="line">              )</span><br><span class="line">            );</span><br><span class="line">          &#125;</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    )</span><br><span class="line">  ],</span><br><span class="line">)</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-cc9fa5b7e7fdc8bf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-%E8%B7%AF%E7%94%B1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-%E8%B7%AF%E7%94%B1/" class="post-title-link" itemprop="url">Flutter-路由</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:44:41 / Modified: 16:45:02" itemprop="dateCreated datePublished" datetime="2020-08-26T16:44:41+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>路由管理就像一个栈，当进入一个新的页面时，就相当于往栈上面增加了一个页面；当退出该页面，返回到之前的页面，就相当于将栈最上面的一个页面拿出</p>
<h2 id="push"><a href="#push" class="headerlink" title="push"></a>push</h2><p>往栈中添加一个新的页面</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">class NavigatorDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      body: Center(</span><br><span class="line">        child: Row(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            FlatButton(</span><br><span class="line">              child: Text(&#39;Home&#39;),</span><br><span class="line">              onPressed: null,</span><br><span class="line">            ),</span><br><span class="line">            FlatButton(</span><br><span class="line">              child: Text(&#39;About&#39;),</span><br><span class="line">              onPressed: ()&#123;</span><br><span class="line">                Navigator.of(context).push( &#x2F;&#x2F; 核心</span><br><span class="line">                  MaterialPageRoute(</span><br><span class="line">                    builder: (BuildContext context) &#x3D;&gt; Page(title: &#39;About&#39;,)</span><br><span class="line">                  )</span><br><span class="line">                );</span><br><span class="line">              &#125;,</span><br><span class="line">            ),</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">class Page extends StatelessWidget &#123;</span><br><span class="line">  final String title;</span><br><span class="line"></span><br><span class="line">  Page(&#123;</span><br><span class="line">    this.title</span><br><span class="line">  &#125;);</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(title),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-8938847d8697f32c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="进入之前"><br><img src="https://upload-images.jianshu.io/upload_images/16731485-f45b4a613fec550c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="点击了About之后"></p>
<h2 id="带名字的路由（Navigator-pushNamed）"><a href="#带名字的路由（Navigator-pushNamed）" class="headerlink" title="带名字的路由（Navigator.pushNamed）"></a>带名字的路由（Navigator.pushNamed）</h2><p>我们可以给要进入的页面路由起一个名字，然后通过<code>Navigator.pushNamed(context, name)</code>方法来完成上面相同的效果<br>首先，我们要在<code>MaterialApp</code>中增加一个属性，叫<code>routes</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">routes: &#123;</span><br><span class="line">  &#39;&#x2F;about&#39;: (context) &#x3D;&gt; Page(title: &#39;About&#39;,),</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">class NavigatorDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      body: Center(</span><br><span class="line">        child: Row(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            FlatButton(</span><br><span class="line">              child: Text(&#39;Home&#39;),</span><br><span class="line">              onPressed: null,</span><br><span class="line">            ),</span><br><span class="line">            FlatButton(</span><br><span class="line">              child: Text(&#39;About&#39;),</span><br><span class="line">              onPressed: ()&#123;</span><br><span class="line">                Navigator.pushNamed(context, &#39;&#x2F;about&#39;); &#x2F;&#x2F; 效果等同于push方法</span><br><span class="line">              &#125;,</span><br><span class="line">            ),</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="pop"><a href="#pop" class="headerlink" title="pop"></a>pop</h2><p>拿出栈中最上面的页面</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">class Page extends StatelessWidget &#123;</span><br><span class="line">  final String title;</span><br><span class="line"></span><br><span class="line">  Page(&#123;</span><br><span class="line">    this.title</span><br><span class="line">  &#125;);</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(title),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">      floatingActionButton: FloatingActionButton(</span><br><span class="line">        child: Icon(Icons.arrow_back),</span><br><span class="line">        onPressed: ()&#123;</span><br><span class="line">          Navigator.pop(context);</span><br><span class="line">        &#125;,</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-5222f08aed6c978f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="添加浮动按钮"></p>
<h2 id="初始路由（initialRoute）"><a href="#初始路由（initialRoute）" class="headerlink" title="初始路由（initialRoute）"></a>初始路由（initialRoute）</h2><p>在<code>MaterialApp</code>中的<code>home</code>属性就是初始路由，当然，我们也可以使用<code>initialRoute</code>属性，首先，我们要先将<code>home</code>属性注释，如下代码所示：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">void main() &#x3D;&gt; runApp(</span><br><span class="line">  new MaterialApp(</span><br><span class="line">    debugShowCheckedModeBanner: false, &#x2F;&#x2F; 消除页面右上角的debug条幅</span><br><span class="line">    title: &#39;江约&#39;,</span><br><span class="line">    &#x2F;&#x2F; home: NavigatorDemo(),</span><br><span class="line">    initialRoute: &#39;&#x2F;about&#39;, &#x2F;&#x2F; 初始路由显示</span><br><span class="line">    routes: &#123;</span><br><span class="line">      &#39;&#x2F;&#39;:(context) &#x3D;&gt; NavigatorDemo(),</span><br><span class="line">      &#39;&#x2F;about&#39;: (context) &#x3D;&gt; Page(title: &#39;About&#39;,),</span><br><span class="line">    &#125;,</span><br><span class="line">  )</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-6748e193cbe35ab2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-Sliver/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-Sliver/" class="post-title-link" itemprop="url">Flutter-Sliver</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:42:59 / Modified: 16:44:23" itemprop="dateCreated datePublished" datetime="2020-08-26T16:42:59+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="网格视图（Sliver）"><a href="#网格视图（Sliver）" class="headerlink" title="网格视图（Sliver）"></a>网格视图（Sliver）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">class SliverDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;SliverDemo&#39;),</span><br><span class="line">      ),</span><br><span class="line">      body: CustomScrollView(</span><br><span class="line">        slivers: &lt;Widget&gt;[</span><br><span class="line">          SliverGrid(</span><br><span class="line">            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(</span><br><span class="line">              crossAxisCount: 2,</span><br><span class="line">              crossAxisSpacing: 8,</span><br><span class="line">              mainAxisSpacing: 8,</span><br><span class="line">              childAspectRatio: 1 &#x2F;&#x2F; 控制该网格视图显示的比例</span><br><span class="line">            ),</span><br><span class="line">            delegate: SliverChildBuilderDelegate(</span><br><span class="line">              (BuildContext context, int index)&#123;</span><br><span class="line">                return Container(</span><br><span class="line">                  child: Image.network(</span><br><span class="line">                    posts[index].imageUrl,</span><br><span class="line">                    fit: BoxFit.cover,</span><br><span class="line">                  ),</span><br><span class="line">                );</span><br><span class="line">              &#125;,</span><br><span class="line">              childCount: posts.length</span><br><span class="line">            ),</span><br><span class="line">          ),</span><br><span class="line">        ],</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-9debf374656acd46.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h3 id="SliverPadding（内边距）"><a href="#SliverPadding（内边距）" class="headerlink" title="SliverPadding（内边距）"></a>SliverPadding（内边距）</h3><p><code>SliverPadding</code>主要为了给<code>SliverGrid</code>创造内边距</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">class SliverDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;SliverDemo&#39;),</span><br><span class="line">      ),</span><br><span class="line">      body: CustomScrollView(</span><br><span class="line">        slivers: &lt;Widget&gt;[</span><br><span class="line">          SliverPadding(</span><br><span class="line">            padding: EdgeInsets.all(8),</span><br><span class="line">            sliver: SliverGridDemo(),</span><br><span class="line">          )</span><br><span class="line">        ],</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">class SliverGridDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return SliverGrid(</span><br><span class="line">      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(</span><br><span class="line">        crossAxisCount: 2,</span><br><span class="line">        crossAxisSpacing: 8,</span><br><span class="line">        mainAxisSpacing: 8,</span><br><span class="line">        childAspectRatio: 1 &#x2F;&#x2F; 控制该网格视图显示的比例</span><br><span class="line">      ),</span><br><span class="line">      delegate: SliverChildBuilderDelegate(</span><br><span class="line">        (BuildContext context, int index)&#123;</span><br><span class="line">          return Container(</span><br><span class="line">            child: Image.network(</span><br><span class="line">              posts[index].imageUrl,</span><br><span class="line">              fit: BoxFit.cover,</span><br><span class="line">            ),</span><br><span class="line">          );</span><br><span class="line">        &#125;,</span><br><span class="line">        childCount: posts.length</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-6beeac267983973d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h3 id="SliverSafeArea（安全区）"><a href="#SliverSafeArea（安全区）" class="headerlink" title="SliverSafeArea（安全区）"></a>SliverSafeArea（安全区）</h3><p>让该网格视图显示在不被手机装饰所遮挡的地方</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">class SliverDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;SliverDemo&#39;),</span><br><span class="line">      ),</span><br><span class="line">      body: CustomScrollView(</span><br><span class="line">        slivers: &lt;Widget&gt;[</span><br><span class="line">          SliverSafeArea(</span><br><span class="line">            sliver: SliverPadding(</span><br><span class="line">              padding: EdgeInsets.all(8),</span><br><span class="line">              sliver: SliverGridDemo(),</span><br><span class="line">            ),</span><br><span class="line">          )</span><br><span class="line">        ],</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="SliverList-ClipRRect（图片圆角）"><a href="#SliverList-ClipRRect（图片圆角）" class="headerlink" title="SliverList + ClipRRect（图片圆角）"></a>SliverList + ClipRRect（图片圆角）</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">class SliverListDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return SliverList(</span><br><span class="line">      delegate: SliverChildBuilderDelegate(</span><br><span class="line">        (BuildContext context, int index)&#123;</span><br><span class="line">          return Padding(</span><br><span class="line">            padding: EdgeInsets.only(bottom: 32),</span><br><span class="line">            child: ClipRRect(</span><br><span class="line">              borderRadius: BorderRadius.circular(12),</span><br><span class="line">              child: Stack(</span><br><span class="line">                children: &lt;Widget&gt;[</span><br><span class="line">                  AspectRatio(</span><br><span class="line">                    aspectRatio: 16&#x2F;9,</span><br><span class="line">                    child: Image.network(</span><br><span class="line">                      posts[index].imageUrl,</span><br><span class="line">                      fit: BoxFit.cover,</span><br><span class="line">                    ),</span><br><span class="line">                  ),</span><br><span class="line">                  Positioned(</span><br><span class="line">                    top: 32,</span><br><span class="line">                    left: 32,</span><br><span class="line">                    child: Column(</span><br><span class="line">                      mainAxisAlignment: MainAxisAlignment.start,</span><br><span class="line">                      children: &lt;Widget&gt;[</span><br><span class="line">                        Text(</span><br><span class="line">                          posts[index].title,</span><br><span class="line">                          style: TextStyle(</span><br><span class="line">                            fontSize: 20,</span><br><span class="line">                            color: Colors.white</span><br><span class="line">                          ),</span><br><span class="line">                        ),</span><br><span class="line">                        Text(</span><br><span class="line">                          posts[index].author,</span><br><span class="line">                          style: TextStyle(</span><br><span class="line">                            fontSize: 13,</span><br><span class="line">                            color: Colors.white</span><br><span class="line">                          ),</span><br><span class="line">                        )</span><br><span class="line">                      ],</span><br><span class="line">                    ),</span><br><span class="line">                  )</span><br><span class="line">                ],</span><br><span class="line">              )</span><br><span class="line">            ),</span><br><span class="line">          );</span><br><span class="line">        &#125;,</span><br><span class="line">        childCount: posts.length</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-aee33d02f0c06439.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h2 id="SliverAppBar（应用工具栏）"><a href="#SliverAppBar（应用工具栏）" class="headerlink" title="SliverAppBar（应用工具栏）"></a>SliverAppBar（应用工具栏）</h2><p>类似于<code>AppBar</code>的导航栏，在默认状态下，我们向下移动就会隐藏导航栏；而想要显示导航栏，必须滑动到页面顶部。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">class SliverDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      body: CustomScrollView(</span><br><span class="line">        slivers: &lt;Widget&gt;[</span><br><span class="line">          SliverAppBar( &#x2F;&#x2F; 类似于APPBar，但滑动到一定程度导航栏会隐藏</span><br><span class="line">            title: Text(&#39;SliverDemo&#39;),</span><br><span class="line">            centerTitle: true, &#x2F;&#x2F; 居中标题</span><br><span class="line">            &#x2F;&#x2F; pinned: true, &#x2F;&#x2F; 将此属性设为true的话，导航栏就会固定在页面上部</span><br><span class="line">            </span><br><span class="line">            &#x2F;&#x2F; 此属性默认为false，我们必须滑到页面顶部，导航栏才会显现；</span><br><span class="line">            &#x2F;&#x2F; 若为true，不管在什么位置，只要稍微向上滑动一点，导航栏就会显现</span><br><span class="line">            &#x2F;&#x2F; floating: true, </span><br><span class="line">          ), </span><br><span class="line">          SliverSafeArea( &#x2F;&#x2F; 安全区</span><br><span class="line">            sliver: SliverPadding( &#x2F;&#x2F; Sliver视图的内边距</span><br><span class="line">              padding: EdgeInsets.all(8),</span><br><span class="line">              sliver: SliverListDemo(),</span><br><span class="line">            ),</span><br><span class="line">          )</span><br><span class="line">        ],</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="待渐进动画的可伸缩空间"><a href="#待渐进动画的可伸缩空间" class="headerlink" title="待渐进动画的可伸缩空间"></a>待渐进动画的可伸缩空间</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">SliverAppBar( &#x2F;&#x2F; 类似于APPBar，但滑动到一定程度导航栏会隐藏</span><br><span class="line">  &#x2F;&#x2F; title: Text(&#39;SliverDemo&#39;),</span><br><span class="line">  centerTitle: true, &#x2F;&#x2F; 居中标题</span><br><span class="line">  &#x2F;&#x2F; pinned: true, &#x2F;&#x2F; 将此属性设为true的话，导航栏就会固定在页面上部</span><br><span class="line"></span><br><span class="line">  &#x2F;&#x2F; 此属性默认为false，我们必须滑到页面顶部，导航栏才会显现；</span><br><span class="line">  &#x2F;&#x2F; 若为true，不管在什么位置，只要稍微向上滑动一点，导航栏就会显现</span><br><span class="line">  &#x2F;&#x2F; floating: true, </span><br><span class="line"></span><br><span class="line">  expandedHeight: 178, &#x2F;&#x2F; 可伸缩控件的高度</span><br><span class="line">  flexibleSpace: FlexibleSpaceBar( &#x2F;&#x2F; 可伸缩空间的具体样式</span><br><span class="line">    title: Text(</span><br><span class="line">      &#39;Ninghao Flutter&#39;.toUpperCase(),</span><br><span class="line">      style: TextStyle(</span><br><span class="line">        fontSize: 15,</span><br><span class="line">        letterSpacing: 3,</span><br><span class="line">        fontWeight: FontWeight.w400</span><br><span class="line">      ),</span><br><span class="line">    ),</span><br><span class="line">    background: Image.network( &#x2F;&#x2F; 背景</span><br><span class="line">      &#39;https:&#x2F;&#x2F;resources.ninghao.org&#x2F;images&#x2F;overkill.png&#39;,</span><br><span class="line">      fit: BoxFit.cover,</span><br><span class="line">    ),</span><br><span class="line">    centerTitle: true,</span><br><span class="line">  ),</span><br><span class="line">), </span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-6ae85f4d564219d6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-%E8%A7%86%E5%9B%BE/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-%E8%A7%86%E5%9B%BE/" class="post-title-link" itemprop="url">Flutter-视图</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:42:22 / Modified: 16:42:46" itemprop="dateCreated datePublished" datetime="2020-08-26T16:42:22+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="滑动视图（PageView）"><a href="#滑动视图（PageView）" class="headerlink" title="滑动视图（PageView）"></a>滑动视图（PageView）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line">class ViewDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return PageView(</span><br><span class="line">      children: &lt;Widget&gt;[</span><br><span class="line">        Container(</span><br><span class="line">          color: Colors.brown[900],</span><br><span class="line">          alignment: Alignment.center,</span><br><span class="line">          child: Text(</span><br><span class="line">            &#39;ONE&#39;,</span><br><span class="line">            style: TextStyle(</span><br><span class="line">              fontSize: 32,</span><br><span class="line">              color: Colors.white</span><br><span class="line">            ),</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">        Container(</span><br><span class="line">          color: Colors.grey[900],</span><br><span class="line">          alignment: Alignment.center,</span><br><span class="line">          child: Text(</span><br><span class="line">            &#39;TWO&#39;,</span><br><span class="line">            style: TextStyle(</span><br><span class="line">                fontSize: 32,</span><br><span class="line">                color: Colors.white</span><br><span class="line">            ),</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">        Container(</span><br><span class="line">          color: Colors.blueGrey[900],</span><br><span class="line">          alignment: Alignment.center,</span><br><span class="line">          child: Text(</span><br><span class="line">            &#39;THREE&#39;,</span><br><span class="line">            style: TextStyle(</span><br><span class="line">                fontSize: 32,</span><br><span class="line">                color: Colors.white</span><br><span class="line">            ),</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">      ],</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-a11e48e35ea64c30.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h3 id="主要属性"><a href="#主要属性" class="headerlink" title="主要属性"></a>主要属性</h3><h4 id="不知道起什么中文名的属性（pageSnapping）"><a href="#不知道起什么中文名的属性（pageSnapping）" class="headerlink" title="不知道起什么中文名的属性（pageSnapping）"></a>不知道起什么中文名的属性（pageSnapping）</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 将此属性设置为false，不管划到什么程度，视图都会停下来，而不是强制显示一个完整的视图</span><br><span class="line">pageSnapping: false, </span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-7d1b2d634e9ece78.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h4 id="反转（reserve）"><a href="#反转（reserve）" class="headerlink" title="反转（reserve）"></a>反转（reserve）</h4><p>视图会发生反转，第一个会变成最后一个</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">reverse: true, &#x2F;&#x2F; 反转</span><br></pre></td></tr></table></figure>
<h4 id="滚动方向（scrollDirection）"><a href="#滚动方向（scrollDirection）" class="headerlink" title="滚动方向（scrollDirection）"></a>滚动方向（scrollDirection）</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">scrollDirection: Axis.vertical, &#x2F;&#x2F; 滚动方向。默认为horizontal</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-997d57361785b261.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="滚动方向"></p>
<h4 id="onPageChanged"><a href="#onPageChanged" class="headerlink" title="onPageChanged"></a>onPageChanged</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onPageChanged: (currentPage) &#x3D;&gt; debugPrint(&#39;Page: $currentPage&#39;), &#x2F;&#x2F; 当切换到其他视图时会触发这个函数</span><br></pre></td></tr></table></figure>
<h4 id="controller"><a href="#controller" class="headerlink" title="controller"></a>controller</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">controller: PageController( &#x2F;&#x2F; 设置</span><br><span class="line">  initialPage: 1, &#x2F;&#x2F; 初始显示的页面</span><br><span class="line">  keepPage: false, &#x2F;&#x2F; 是否保存当前Page的状态，initialPage将会被忽略。如果为false，下次总是从initial开始</span><br><span class="line">  viewportFraction: 1 &#x2F;&#x2F; 占屏幕多少</span><br><span class="line">),</span><br></pre></td></tr></table></figure>
<h3 id="builder"><a href="#builder" class="headerlink" title="builder"></a>builder</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">class PageViewBuilderDemo extends StatelessWidget &#123;</span><br><span class="line">  Widget _pageItemBuilder(BuildContext context, int index)&#123;</span><br><span class="line">    return Stack(</span><br><span class="line">      children: &lt;Widget&gt;[</span><br><span class="line">        SizedBox.expand(</span><br><span class="line">          child: Image.network(</span><br><span class="line">            posts[index].imageUrl,</span><br><span class="line">            fit: BoxFit.cover,</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">        Positioned(</span><br><span class="line">          bottom: 8,</span><br><span class="line">          left: 8,</span><br><span class="line">          child: Column(</span><br><span class="line">            crossAxisAlignment: CrossAxisAlignment.start,</span><br><span class="line">            children: &lt;Widget&gt;[</span><br><span class="line">              Text(</span><br><span class="line">                posts[index].title,</span><br><span class="line">                style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),</span><br><span class="line">              ),</span><br><span class="line">              Text(</span><br><span class="line">                posts[index].author,</span><br><span class="line">              )</span><br><span class="line">            ],</span><br><span class="line">          ),</span><br><span class="line">        )</span><br><span class="line">      ],</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return PageView.builder(</span><br><span class="line">      itemCount: posts.length, &#x2F;&#x2F; 数量</span><br><span class="line">      itemBuilder: _pageItemBuilder, &#x2F;&#x2F; 构造方法</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-917ad5ed46c0a479.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h2 id="网格视图（GridView）"><a href="#网格视图（GridView）" class="headerlink" title="网格视图（GridView）"></a>网格视图（GridView）</h2><h3 id="count"><a href="#count" class="headerlink" title="count"></a>count</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">class GridViewCountDemo extends StatelessWidget &#123;</span><br><span class="line">  List&lt;Widget&gt; _buildTiles(int length)&#123;</span><br><span class="line">    return List.generate(length, (int index)&#123;</span><br><span class="line">      return Container(</span><br><span class="line">        color: Colors.grey[300],</span><br><span class="line">        alignment: Alignment.center,</span><br><span class="line">        child: Text(</span><br><span class="line">          &#39;Item $index&#39;,</span><br><span class="line">          style: TextStyle(fontSize: 18, color: Colors.grey),</span><br><span class="line">        ),</span><br><span class="line">      );</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return GridView.count(</span><br><span class="line">      crossAxisCount: 3, &#x2F;&#x2F; 交叉轴的数量</span><br><span class="line">      crossAxisSpacing: 16, &#x2F;&#x2F; 交叉轴之间的间距</span><br><span class="line">      mainAxisSpacing: 16, &#x2F;&#x2F; 主轴之间的间距</span><br><span class="line">      scrollDirection: Axis.horizontal,</span><br><span class="line">      children: _buildTiles(50),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-9e7201591632bc10.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h3 id="extent"><a href="#extent" class="headerlink" title="extent"></a>extent</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">class GridViewExtentDemo extends StatelessWidget &#123;</span><br><span class="line">  List&lt;Widget&gt; _buildTiles(int length)&#123;</span><br><span class="line">    return List.generate(length, (int index)&#123;</span><br><span class="line">      return Container(</span><br><span class="line">        color: Colors.grey[300],</span><br><span class="line">        alignment: Alignment.center,</span><br><span class="line">        child: Text(</span><br><span class="line">          &#39;Item $index&#39;,</span><br><span class="line">          style: TextStyle(fontSize: 18, color: Colors.grey),</span><br><span class="line">        ),</span><br><span class="line">      );</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return GridView.extent(</span><br><span class="line">      maxCrossAxisExtent: 150, &#x2F;&#x2F; 子项在主轴最大的宽度&#x2F;高度</span><br><span class="line">      crossAxisSpacing: 16,</span><br><span class="line">      mainAxisSpacing: 16,</span><br><span class="line">      scrollDirection: Axis.horizontal,</span><br><span class="line">      children: _buildTiles(50),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-42291b06113f5c4b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h3 id="build"><a href="#build" class="headerlink" title="build"></a>build</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">class GridViewBuilderDemo extends StatelessWidget &#123;</span><br><span class="line">  Widget _gridItemBuilder(BuildContext context, int index)&#123;</span><br><span class="line">    return Container(</span><br><span class="line">      child: Image.network(</span><br><span class="line">        posts[index].imageUrl,</span><br><span class="line">        fit: BoxFit.cover,</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return GridView.builder(</span><br><span class="line">      padding: EdgeInsets.all(8),</span><br><span class="line">      itemCount: posts.length,</span><br><span class="line">      itemBuilder: _gridItemBuilder,</span><br><span class="line">      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( &#x2F;&#x2F; 控制显示</span><br><span class="line">        crossAxisCount: 3, &#x2F;&#x2F; 交叉轴数量为3</span><br><span class="line">        crossAxisSpacing: 16, &#x2F;&#x2F; 交叉轴中各项间距为8</span><br><span class="line">        mainAxisSpacing: 16 &#x2F;&#x2F; 主轴间距为8</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-b6dd63814e7e7c71.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-AspectRadio/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-AspectRadio/" class="post-title-link" itemprop="url">Flutter-AspectRadio</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:41:48 / Modified: 16:42:06" itemprop="dateCreated datePublished" datetime="2020-08-26T16:41:48+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p><code>AspectRatio</code>为调整宽高比的布局</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">class LayoutDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Center(</span><br><span class="line">      child: AspectRatio(</span><br><span class="line">        aspectRatio: 3&#x2F;2, &#x2F;&#x2F; 宽高比为3:2</span><br><span class="line">        child: Container(</span><br><span class="line">          color: Colors.blue,</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-3c3796e222b86ee6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-Border/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-Border/" class="post-title-link" itemprop="url">Flutter-Border</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:41:14 / Modified: 16:41:32" itemprop="dateCreated datePublished" datetime="2020-08-26T16:41:14+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="边框（Border）"><a href="#边框（Border）" class="headerlink" title="边框（Border）"></a>边框（Border）</h2><h3 id="单侧边框"><a href="#单侧边框" class="headerlink" title="单侧边框"></a>单侧边框</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">class BasicDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Container(</span><br><span class="line">      color: Colors.grey[100],</span><br><span class="line">      child: Row(</span><br><span class="line">        mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">        children: &lt;Widget&gt;[</span><br><span class="line">          Container(</span><br><span class="line">            child: Icon(Icons.pool, size: 32, color: Colors.white,),</span><br><span class="line">            padding: EdgeInsets.all(16),</span><br><span class="line">            margin: EdgeInsets.all(8),</span><br><span class="line">            width: 90,</span><br><span class="line">            height: 90,</span><br><span class="line">            decoration: BoxDecoration(</span><br><span class="line">              color: Color.fromRGBO(3, 54, 255, 1),</span><br><span class="line">              border: Border(</span><br><span class="line">                top: BorderSide( &#x2F;&#x2F; 设置单侧边框的样式</span><br><span class="line">                  color: Colors.indigoAccent[100],</span><br><span class="line">                  width: 3,</span><br><span class="line">                  style: BorderStyle.solid</span><br><span class="line">                )</span><br><span class="line">              )</span><br><span class="line">            ),</span><br><span class="line">          )</span><br><span class="line">        ],</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-875046abae1d2245.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h3 id="全部边框"><a href="#全部边框" class="headerlink" title="全部边框"></a>全部边框</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">border: Border.all(</span><br><span class="line">  color: Colors.indigoAccent[100],</span><br><span class="line">  width: 3,</span><br><span class="line">  style: BorderStyle.solid</span><br><span class="line">)</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-b2fef483b6d77505.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h2 id="圆角（borderRadius）"><a href="#圆角（borderRadius）" class="headerlink" title="圆角（borderRadius）"></a>圆角（borderRadius）</h2><h3 id="全部圆角"><a href="#全部圆角" class="headerlink" title="全部圆角"></a>全部圆角</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">decoration: BoxDecoration(</span><br><span class="line">  color: Color.fromRGBO(3, 54, 255, 1),</span><br><span class="line">  border: Border.all(</span><br><span class="line">    color: Colors.indigoAccent[100],</span><br><span class="line">    width: 3,</span><br><span class="line">    style: BorderStyle.solid</span><br><span class="line">  ),</span><br><span class="line">  borderRadius: BorderRadius.circular(16), &#x2F;&#x2F; 设置四周圆角 </span><br><span class="line">),</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-20c9106a227387ea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h3 id="单侧圆角"><a href="#单侧圆角" class="headerlink" title="单侧圆角"></a>单侧圆角</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">borderRadius: BorderRadius.only(</span><br><span class="line">  topLeft: Radius.circular(64)</span><br><span class="line">),</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-d8f822bc51d38ee7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h2 id="阴影（BoxShadow）"><a href="#阴影（BoxShadow）" class="headerlink" title="阴影（BoxShadow）"></a>阴影（BoxShadow）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">boxShadow: [</span><br><span class="line">  BoxShadow(</span><br><span class="line">    offset: Offset(6, 7), &#x2F;&#x2F; 阴影的偏移量</span><br><span class="line">    color: Color.fromRGBO(16, 20, 188, 1), &#x2F;&#x2F; 阴影的颜色</span><br><span class="line">    blurRadius: 5, &#x2F;&#x2F; 阴影的模糊程度</span><br><span class="line">    spreadRadius: 0, &#x2F;&#x2F; 扩散的程度，如果设置成正数，则会扩大阴影面积；负数的话，则会缩小阴影面积</span><br><span class="line">  )</span><br><span class="line">],</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-1ed156458cf64b52.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h2 id="形状（shape）"><a href="#形状（shape）" class="headerlink" title="形状（shape）"></a>形状（shape）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">class BasicDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Container(</span><br><span class="line">      color: Colors.grey[100],</span><br><span class="line">      child: Row(</span><br><span class="line">        mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">        children: &lt;Widget&gt;[</span><br><span class="line">          Container(</span><br><span class="line">            child: Icon(Icons.pool, size: 32, color: Colors.white,),</span><br><span class="line">            padding: EdgeInsets.all(16),</span><br><span class="line">            margin: EdgeInsets.all(8),</span><br><span class="line">            width: 90,</span><br><span class="line">            height: 90,</span><br><span class="line">            decoration: BoxDecoration(</span><br><span class="line">              color: Color.fromRGBO(3, 54, 255, 1),</span><br><span class="line">              border: Border.all(</span><br><span class="line">                color: Colors.indigoAccent[100],</span><br><span class="line">                width: 3,</span><br><span class="line">                style: BorderStyle.solid</span><br><span class="line">              ),</span><br><span class="line">&#x2F;&#x2F;              borderRadius: BorderRadius.circular(16), &#x2F;&#x2F; 设置四周圆角</span><br><span class="line">              boxShadow: [</span><br><span class="line">                BoxShadow(</span><br><span class="line">                  offset: Offset(6, 7), &#x2F;&#x2F; 阴影的偏移量</span><br><span class="line">                  color: Color.fromRGBO(16, 20, 188, 1), &#x2F;&#x2F; 阴影的颜色</span><br><span class="line">                  blurRadius: 5, &#x2F;&#x2F; 阴影的模糊程度</span><br><span class="line">                  spreadRadius: 0, &#x2F;&#x2F; 扩散的程度，如果设置成正数，则会扩大阴影面积；负数的话，则会缩小阴影面积</span><br><span class="line">                )</span><br><span class="line">              ],</span><br><span class="line">              shape: BoxShape.circle, &#x2F;&#x2F; 将其形状设置为圆形，但此形状不能设置圆角属性</span><br><span class="line">            ),</span><br><span class="line">          )</span><br><span class="line">        ],</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-c6cf0f31fd50d325.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h2 id="渐变（gradient）"><a href="#渐变（gradient）" class="headerlink" title="渐变（gradient）"></a>渐变（gradient）</h2><h3 id="圆形渐变"><a href="#圆形渐变" class="headerlink" title="圆形渐变"></a>圆形渐变</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">gradient: RadialGradient( &#x2F;&#x2F; 圆形渐变，从中心开始渐变</span><br><span class="line">  colors: [</span><br><span class="line">    Color.fromRGBO(7, 102, 255, 1),</span><br><span class="line">    Color.fromRGBO(3, 28, 128, 1)</span><br><span class="line">  ]</span><br><span class="line">),</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-f25a694fc0eb9c7a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h3 id="线性渐变"><a href="#线性渐变" class="headerlink" title="线性渐变"></a>线性渐变</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">gradient: LinearGradient( &#x2F;&#x2F; 线性渐变，如果没有指定开始和结束的地方，则默认从左边到右边</span><br><span class="line">  colors: [</span><br><span class="line">    Color.fromRGBO(7, 102, 255, 1),</span><br><span class="line">    Color.fromRGBO(3, 28, 128, 1)</span><br><span class="line">  ],</span><br><span class="line">  begin: Alignment.topCenter, &#x2F;&#x2F; 开始</span><br><span class="line">  end: Alignment.bottomCenter, &#x2F;&#x2F; 结束</span><br><span class="line">),</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-f5eca90d76d30534.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="背景图像"><a href="#背景图像" class="headerlink" title="背景图像"></a>背景图像</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">decoration: BoxDecoration(</span><br><span class="line">  image: DecorationImage(</span><br><span class="line">    image: NetworkImage(&#39;https:&#x2F;&#x2F;resources.ninghao.org&#x2F;images&#x2F;say-hello-to-barry.jpg&#39;),</span><br><span class="line">    alignment: Alignment.topCenter,</span><br><span class="line">&#x2F;&#x2F;  repeat: ImageRepeat.repeatY &#x2F;&#x2F; 重复程度</span><br><span class="line">    fit: BoxFit.cover,</span><br><span class="line">    colorFilter: ColorFilter.mode(</span><br><span class="line">      Colors.indigoAccent[400].withOpacity(0.5), &#x2F;&#x2F; 滤镜颜色</span><br><span class="line">      BlendMode.hardLight, &#x2F;&#x2F; 滤镜模式</span><br><span class="line">    ),</span><br><span class="line">  )</span><br><span class="line">),</span><br><span class="line">&#x2F;&#x2F;      color: Colors.grey[100], &#x2F;&#x2F; 该属性为Container背景颜色，若有decoration属性，该属性可不需要</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-723b09ad33761996.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-RichText/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-RichText/" class="post-title-link" itemprop="url">Flutter-RichText</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:40:32 / Modified: 16:40:57" itemprop="dateCreated datePublished" datetime="2020-08-26T16:40:32+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>可在一行文字里定义多种样式</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">class BasicDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return RichText(</span><br><span class="line">      text: TextSpan(</span><br><span class="line">        text: &#39;ninghao&#39;,</span><br><span class="line">        style: TextStyle(</span><br><span class="line">          color: Colors.deepPurpleAccent,</span><br><span class="line">          fontSize: 34,</span><br><span class="line">          fontStyle: FontStyle.italic, &#x2F;&#x2F; 斜体</span><br><span class="line">          fontWeight: FontWeight.w100, &#x2F;&#x2F; 文字的粗细</span><br><span class="line">        ),</span><br><span class="line">        children: [</span><br><span class="line">          TextSpan(</span><br><span class="line">            text: &#39;.net&#39;,</span><br><span class="line">            style: TextStyle(</span><br><span class="line">              fontSize: 17,</span><br><span class="line">              color: Colors.black</span><br><span class="line">            )</span><br><span class="line">          )</span><br><span class="line">        ]</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-bc0d893a27e6bc05.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/hexo/page/6/"><i class="fa fa-angle-left" aria-label="Previous page"></i></a><a class="page-number" href="/hexo/">1</a><span class="space">&hellip;</span><a class="page-number" href="/hexo/page/6/">6</a><span class="page-number current">7</span><a class="page-number" href="/hexo/page/8/">8</a><span class="space">&hellip;</span><a class="page-number" href="/hexo/page/13/">13</a><a class="extend next" rel="next" href="/hexo/page/8/"><i class="fa fa-angle-right" aria-label="Next page"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="幽辰"
      src="/hexo/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">幽辰</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/hexo/archives/">
        
          <span class="site-state-item-count">127</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/hexo/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/hexo/tags/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">幽辰</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a>
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/hexo/lib/anime.min.js"></script>
  <script src="/hexo/lib/velocity/velocity.min.js"></script>
  <script src="/hexo/lib/velocity/velocity.ui.min.js"></script>

<script src="/hexo/js/utils.js"></script>

<script src="/hexo/js/motion.js"></script>


<script src="/hexo/js/schemes/pisces.js"></script>


<script src="/hexo/js/next-boot.js"></script>




  















  

  

</body>
</html>
